<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"  />
<xsl:template match="/">/*******************************************************************************
** File Name:		     <xsl:value-of select="@NameSpace" />.cs
** Creator:		       <xsl:value-of select="Schema/@UserName" />
** EMail:            <xsl:value-of select="Schema/@UserEMail" /> 
** Create date:	     <xsl:value-of select="Schema/@ModifyDate" />
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
<xsl:value-of select="Schema/@UsingNamespace" />

  /// <summary>
	/// <xsl:value-of select="Schema/@TableName" />所有记录的分页列表
	/// </summary>
  public partial class <xsl:value-of select="Schema/@TableName" />List : <xsl:value-of select="Schema/@BasePageClass" />
  {
      GridViewHelper gridHelper;
      private void Page_Load(object sender, System.EventArgs e)
      {
      LanguageSelect.LanguageChanged += new LanguageChangeHandler(this.LanguageChanged);
      if(!IsPostBack)
      {
      //判断权限
      //if (!CheckRight("EmployeeAdmin"))
      //{
      //NoRightAlert();
      //}
      }
      gridHelper = new GridViewHelper(gvResult, "cbxSelect");
      gridPager.PageChanged += new EventHandler(gridPager_PageChanged);

      gridHelper.AttachMustOneRowCheck(btnView);
      gridHelper.AttachMustOneRowCheck(btnUpdate);
      gridHelper.AttachDeleteCheck(btnDelete);

      if (!IsPostBack)
      {
        // 初始化语言下拉框
        LanguageSelect.InitLanguageData();
        // 获取语言参数，并赋给控件。

        string strLanguageID = (string)QueryTable["LanguageID"];
        if (strLanguageID != null <xsl:text disable-output-escaping="yes">&amp;</xsl:text><xsl:text disable-output-escaping="yes">&amp;</xsl:text> strLanguageID != "")
        LanguageSelect.LanguageID = strLanguageID;

        LanguageID = LanguageSelect.LanguageID;

        BindData();
      }

    }

    /// <summary>
    /// 当语言变化时，把语言编号保存在ViewState中
    /// </summary>
    private void LanguageChanged(object sender, System.EventArgs e)
    {
      LanguageID = LanguageSelect.LanguageID;
      BindData();
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    private void BindData()
    {
      string order = gridHelper.GetOrderBy();

      DateTime dtDefault = new DateTime(1900, 1, 1);
      int CurrentPage = gridPager.CurrentPage;
      int TotalPage = 0;
      int TotalRecord = 0;
      //TODO:
      //DataTable dtQuery = <xsl:value-of select="Schema/@TableName" />Biz.Get<xsl:value-of select="Schema/@TableName" />ByConditions(condition, 
      //            gridPager.PageSize, ref CurrentPage, out TotalPage, out TotalRecord, order);
      DataTable dtQuery = <xsl:value-of select="Schema/@TableName" />Biz.GetAll<xsl:value-of select="Schema/@TableName" />();

      // 绑定
      gvResult.DataSource = dtQuery;
      gvResult.DataBind();

      //gridPager.TotalItems = TotalRecord;
      gridPager.TotalItems = dtQuery.Rows.Count;
      gridPager.DataBind();

    }

    protected void gvResult_Sorting(object sender, GridViewSortEventArgs e)
    {
      gridHelper.SetOrderBy(e.SortExpression, e.SortDirection);
      gridPager.ResetCurrentPage();
      BindData();
    }

    protected void gridPager_PageChanged(object sender, EventArgs e)
    {
      BindData();
    }

    protected void btnView_Click(object sender, EventArgs e)
    {
      Response.Redirect("<xsl:value-of select="Schema/@TableName" />View.aspx?q=" + GetEncryptQueryString("<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>=" + gridHelper.GetSelectedStringKeys()[0]));
    }

    protected void btnInsert_Click(object sender, EventArgs e)
    {
      Response.Redirect("<xsl:value-of select="Schema/@TableName" />edit.aspx?q=" + GetEncryptQueryString("Action=add"));
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
      Response.Redirect("<xsl:value-of select="Schema/@TableName" />edit.aspx?q=" + GetEncryptQueryString("Action=edit&amp;<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>=" + gridHelper.GetSelectedStringKeys()[0]));
	  }

	  protected void gvResult_RowCommand(object sender, GridViewCommandEventArgs e)
	  {
      	    //TODO:实现删除的代码
            if (e.CommandName == "Del")
            {
                //获取条件参数
                try
                {
                    //删除或更新实体
                }
                catch (Exception ex)
                {
                    lblMessage.Text = "删除失败，<br />" + ex.Message;
                    return;
                }
                BindData();
            }
      
	  }

	  protected void btnDelete_Click(object sender, EventArgs e)
	  {
	    //TODO:实现批量删除的代码
	  }

	  protected void btnSearch_Click(object sender, EventArgs e)
	  {
  	  BindData();
	  }

	}
</xsl:template>
</xsl:stylesheet>